package obj;

import play.Things;

/**
 * Moving platform class.
 * @author VincentLy
 */
public class MovingPlatform extends Platform{

	private float origX;
	private float origY;
	private float prevX;
	private float prevY;
	private float movementX;
	private float movementY;
	private float extent;
	
	public MovingPlatform(float x,float y,float l,float w,int c,int i,float xm,float ym,float e) {
		super(x,y,l,w,c,i);	
		origX = x();
		origY = y();
		movementX = xm;
		movementY = ym;
		extent = e;
	}
	
	/**
	 * Moves the platform back and forth within specified bounds.
	 * @author VincentLy
	 */
	public void update(){
		prevX = x();
		prevY = y();
		move(x()+movementX,y() + movementY);
		if(Things.player.platform()==this)
			Things.player.move(Things.player.x()+movementX,Things.player.y()+movementY);
		if(Math.abs(x()-origX)>extent)
			movementX*=-1;
		if(Math.abs(y()-origY)>extent)
			movementY*=-1;
	}
	
	/**
	 * @return previous x location
	 * @author VincentLy
	 */
	public float xprev(){return prevX;}
	
	/**
	 * @return previous y location
	 * @author VincentLy
	 */
	public float yprev(){return prevY;}
}